<?php

class App_mod_carriers extends MY_Model {

function __construct()
{
	parent::__construct();
}

public function change_status($carrier_id, $status)
{
	$data['status'] = $status;
	
	// change status in carriers table
	$this->db->where('id',$carrier_id)->update('carriers',$data);

	$carrier = $this->PACKAGE->routing->carriers->get_carrier_as_array_by_id($carrier_id);
	
	// change statuses in other tables
	switch($carrier['contract_type'])
	{		
		case "we_buy_from_them":
			// termination_trunks table
			unset($data);
			$data['carrier_status'] = $status;
			$this->db->where('carrier_id',$carrier_id)->update('termination_trunks',$data);
			
			// relations_origin_termination table
			unset($data);
			$data['termination_carrier_status'] = $status;
			$this->db->where('termination_carrier_id',$carrier_id)->update('relations_origin_termination',$data);			
		break;
		
		case "we_sell_to_them":
			// origin_trunks table
			unset($data);
			$data['carrier_status'] = $status;
			$this->db->where('carrier_id',$carrier_id)->update('origin_trunks',$data);
		break;

		case "bi_lateral":
			// termination_trunks table
			unset($data);
			$data['carrier_status'] = $status;
			$this->db->where('carrier_id',$carrier_id)->update('termination_trunks',$data);
			
			// relations_origin_termination table
			unset($data);
			$data['termination_carrier_status'] = $status;
			$this->db->where('termination_carrier_id',$carrier_id)->update('relations_origin_termination',$data);			

			// origin_trunks table
			unset($data);
			$data['carrier_status'] = $status;
			$this->db->where('carrier_id',$carrier_id)->update('origin_trunks',$data);					
		break;		
	}
	
	// alternatively!!!
	$this->APPLICATION->load->model('app_mod_cron');
	$this->APPLICATION->app_mod_cron->update_final_routing_statuses();
	
	return true;
}	


}